﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入账号" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
                <td style="padding-left: 10px;">
                    <div id="time_horizon" class="btn-group">
                        <a class="btn btn-default" data-value="1">今天</a>
                        <a class="btn btn-default active" data-value="2">近7天</a>
                        <a class="btn btn-default" data-value="3">近1个月</a>
                        <a class="btn btn-default" data-value="4">近3个月</a>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

<script>
    $(function () {
        gridList();
    })

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/SystemManage/SysLog/GetPagintionGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'Id', hidden: true },
                {
                    label: '日期', name: 'Date', width: 120, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                { label: '账号', name: 'Account', width: 80, align: 'left' },
                { label: '姓名', name: 'NickName', width: 80, align: 'left' },
                { label: '操作菜单', name: 'ModuleName', width: 100, align: 'left' },
                {
                    label: '操作类型', name: 'Type', width: 80, align: 'left',
                    formatter: function (cellvalue) {
                        return $.itemDetails.getNameByCode('DbLogType', cellvalue);
                    }
                },
                {
                    label: 'IP地址', name: 'IPAddress', width: 230, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue && IPAddressName) {
                            return cellvalue + ";" + rowObject.IPAddressName;
                        }
                        else {
                            return "";
                        }
                    }
                },
                { label: '日志内容', name: 'Description', width: 300, align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'Date desc',
            viewrecords: true
        });

        $("#time_horizon a.btn-default").click(function () {
            $("#time_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });

        $("#btn_search").click(function () {
            var timeType = $("#time_horizon a.active").attr('data-value');
            var queryJson = {
                keyword: $("#txt_keyword").val(),
                timeType: $("#time_horizon a.active").attr('data-value'),
            }
            $gridList.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
                page: 1,
            }).trigger('reloadGrid');
        });

        //回车触发查询事件
        $('#txt_keyword').keydownEnterEvent(function () {
            $('#btn_search').trigger('click');
        })
    }

</script>